/**
 * 抽奖碎片页嵌入
 * @author: luzhaoman
 * @modified: jinguangguo
 */
var ajaxUrlPrefix = "http://app-02.my.17173.com/qiangba/";
var	resUrlPrefix = "http://app-02.my.17173.com/qiangba/";
	
var createQbFragment = (function ($) {
	
	//创建碎片- createQbFragment
	return function (opt){
		
		if (opt.width) {
			opt.width = parseInt(opt.width);
		}
		$.ajax({
		   url: ajaxUrlPrefix+"/draw/getFragment.do",
		   data: "topWinner="+opt.topWinner+"&activeId="+opt.activeId+"&height="+opt.height+"&width="+opt.width,
		   dataType:"jsonp",
	       jsonp:"jsonpcallback",
		   success: function(msg){
			   //先加载css文件
			   var cssStr = '<link href="http://ue1.17173.itc.cn/2011/17173my/css/win-skin.css" rel="stylesheet" rev="stylesheet" media="all">\
				   			<link href="http://ue1.17173.itc.cn/2011/17173my/css/win-con.css" rel="stylesheet" rev="stylesheet" media="all">\
							<link href="'+resUrlPrefix+'/css/disk/app-qiangba-disk.css" rel="stylesheet" type="text/css" />';
			   $('head').first().append(cssStr);
			   //再加载js文件
			   $.getScript(resUrlPrefix + 'js/disk/disk.js', function () {
				   	$.getScript(resUrlPrefix + 'js/disk/playdisk.js', function () {
						//拼写HTML
						var html = "";
						switch (opt.width) {
                        case 250:
                        	html = dom250(msg);
                        	break;
                        case 420:
                        	html = dom420(msg);
                        	break;
                        case 580:
                        	html = dom580(msg);
                        	break;
                        case 800:
                        	html = dom800(msg);
                        	break;
                        case 900:
                        	html = dom900(msg);
                        	break;
                        default:
                        	alert('碎片尺寸不正确，请纠正！');
                        	return;
                        }

						html += getActiveEndScript(msg);
						$("#diskWrapper").empty().append(html);
						// 滚动名单
						scrollNameList();
					});
				});
			   
		   }
		});
	}
	
	//活动结束
	function getActiveEndScript(fragment){
		if(fragment.active.activeIsEnd){
			return '<script type="text/javascript">activeFinished();</script>';
		}
		return "";
	}

	//用户信息
	function getWelcome(fragment){
		if(fragment.loginable){
			return "<span>亲爱的</span><em>"+fragment.nickname+"</em><span>您还剩</span><i>"+fragment.userGB+"G币</i>";
		}else{
			return "<span>亲爱的</span>用户，欢迎欢迎!</i>";
		}
	}

	//奖盘按钮文字
	function getChoujiangLable(fragment){
		if(fragment.gCost==0){
			return "<em>立即</em><i>抽奖</i>";
		}else{
			return "<em>"+fragment.gCost+"G</em><i>抽奖</i>";
		}
	}

	//奖盘
	function getDiskTable(fragment){
		var jiuGongGeExList = fragment.jiuGongGeExList;
		
		var str='<table>\
					<tbody>\
						<tr>\
							<td>\
								<img src="'+jiuGongGeExList[0].awardImage+'">\
								<span>'+jiuGongGeExList[0].awardName+'</span>\
							</td>\
							<td>\
								<img src="'+jiuGongGeExList[1].awardImage+'">\
								<span>'+jiuGongGeExList[1].awardName+'</span>\
							</td>\
							<td>\
								<img src="'+jiuGongGeExList[2].awardImage+'">\
								<span>'+jiuGongGeExList[2].awardName+'</span>\
							</td>\
						</tr>\
						<tr>\
							<td>\
								<img src="'+jiuGongGeExList[7].awardImage+'">\
								<span>'+jiuGongGeExList[7].awardName+'</span>\
							</td>\
							<td class="disk-btn-center">\
								<span class="disk-btn disk-btn-start link hand" id="disk-start">'+getChoujiangLable(fragment)+'</span>\
							</td>\
							<td>\
								<img src="'+jiuGongGeExList[3].awardImage+'">\
								<span>'+jiuGongGeExList[3].awardName+'</span>\
							</td>\
						</tr>\
						<tr>\
							<td>\
								<img src="'+jiuGongGeExList[6].awardImage+'">\
								<span>'+jiuGongGeExList[6].awardName+'</span>\
							</td>\
							<td>\
								<img src="'+jiuGongGeExList[5].awardImage+'">\
								<span>'+jiuGongGeExList[5].awardName+'</span>\
							</td>\
							<td>\
								<img src="'+jiuGongGeExList[4].awardImage+'">\
								<span>'+jiuGongGeExList[4].awardName+'</span>\
							</td>\
						</tr>\
					</tbody>\
				</table>';
		return str;
	}

	//js文件-spp登录验证
	function getResource4qb1(fragment){
		var str="";
		//登录所需JS文件
		str += '<script src="'+resUrlPrefix+'/js/city.js"></script>';
		
		str += '<script type="text/javascript">\
					var gameCode="'+fragment.active.gameCode+'";\
					var activeId="'+fragment.active.id+'";\
				</script>';
		
		return str;
	}

	//获奖名单
	function getTopWinner4qb(fragment){
		var topWinnerList = fragment.topWinnerList || [];
		var str="";
		str+='<div class="mod-anl fr">\
				<div class="mod-anl-wrapper">\
					<div class="a-title">\
						<h4>获奖用户</h4>\
					</div>\
					<div class="a-main">\
					<div class="cont">';
		for(var i=0;i<topWinnerList.length;i++){
			winner=topWinnerList[i];
			str+='<p>\
				<a title="'+winner.nickname +'" href="javascript:void(0);">'+winner.nickname+'</a>\
				<span>'+winner.winTimeStr +'中了</span>\
				<em title="' + winner.awardName + '">'+winner.awardName +'</em>\
				</p>';
		}
		
		str += '</div></div></div></div>';
					
		return str;
	}

	//盘250
	function dom250(fragment){
		var str="";
		str+=getResource4qb1(fragment);
		str+='<div class="i-disk">\
				<div class="implant-wrapper">\
					<div class="user-info">'+getWelcome(fragment)+'</div>\
					<div id="disk" class="disk-wrapper disk-250">\
						<div class="box-disk box-disk-tp">\
							<i class="box-disk-edge tp-left">&nbsp;</i>\
							<i class="box-disk-edge tp-right">&nbsp;</i>\
						</div>\
						<div class="box-disk-cont">\
							<div class="table-wrapper">'+getDiskTable(fragment)+'</div>\
						</div>\
						<div class="box-disk box-disk-bt">\
							<i class="box-disk-edge bt-left">&nbsp;</i>\
							<i class="box-disk-edge bt-right">&nbsp;</i>\
						</div>\
					</div>\
				</div>\
				</div>';
					
		return str;
	}

	//盘420
	function dom420(fragment){
		var str="";
		str=getResource4qb1(fragment);
		str+='	<div class="i-disk">\
				<div class="implant-wrapper">\
					<div class="user-info">'+getWelcome(fragment)+'</div>\
					<div id="disk" class="disk-wrapper disk-420">\
						<div class="box-disk box-disk-tp">\
							<i class="box-disk-edge tp-left">&nbsp;</i>\
							<i class="box-disk-edge tp-right">&nbsp;</i>\
						</div>\
						<div class="box-disk-cont">\
							<div class="table-wrapper">'+getDiskTable(fragment)+'</div>\
						</div>\
						<div class="box-disk box-disk-bt">\
							<i class="box-disk-edge bt-left">&nbsp;</i>\
							<i class="box-disk-edge bt-right">&nbsp;</i>\
						</div>\
					</div>\
				</div>\
				</div>';
					
		return str;
	}

	//盘580
	function dom580(fragment){
		var str="";
		str=getResource4qb1(fragment);
		str+='	<div class="i-disk">\
				<div class="implant-wrapper">\
					<div class="user-info">'+getWelcome(fragment)+'</div>\
					<div id="disk" class="disk-wrapper disk-580">\
						<div class="box-disk box-disk-tp">\
							<i class="box-disk-edge tp-left">&nbsp;</i>\
							<i class="box-disk-edge tp-right">&nbsp;</i>\
						</div>\
						<div class="box-disk-cont">\
							<div class="table-wrapper">'+getDiskTable(fragment)+'</div>\
						</div>\
						<div class="box-disk box-disk-bt">\
							<i class="box-disk-edge bt-left">&nbsp;</i>\
							<i class="box-disk-edge bt-right">&nbsp;</i>\
						</div>\
					</div>\
				</div>\
				</div>';
					
		return str;
	}

	//盘800
	function dom800(fragment){
		var str="";
		str = getResource4qb1(fragment);
		str += '<div class="i-disk">\
					<div class="i-disk i-disk-800">\
						<div class="implant-wrapper">\
							<div class="user-info">'+getWelcome(fragment)+'</div>\
							<div class="content-wapper clearfix">\
								<div id="disk" class="disk-wrapper disk-450 fl">\
									<div class="box-disk box-disk-tp">\
										<i class="box-disk-edge tp-left">&nbsp;</i>\
										<i class="box-disk-edge tp-right">&nbsp;</i>\
									</div>\
									<div class="box-disk-cont">\
										<div class="table-wrapper">'+getDiskTable(fragment)+'</div>\
									</div>\
									<div class="box-disk box-disk-bt">\
										<i class="box-disk-edge bt-left">&nbsp;</i>\
										<i class="box-disk-edge bt-right">&nbsp;</i>\
									</div>\
								</div>';
		str += getTopWinner4qb(fragment);	
		str+=	'</div></div></div>';		
		return str;
	}

	//盘900
	function dom900(fragment){
		var str="";
		str=getResource4qb1(fragment);
		str += '<div class="i-disk">\
				<div class="i-disk i-disk-900">\
					<div class="user-info">'+getWelcome(fragment)+'</div>\
					<div id="disk" class="disk-wrapper disk-580 fl">\
						<div class="box-disk box-disk-tp">\
							<i class="box-disk-edge tp-left">&nbsp;</i>\
							<i class="box-disk-edge tp-right">&nbsp;</i>\
						</div>\
						<div class="box-disk-cont">\
							<div class="table-wrapper">'+getDiskTable(fragment)+'</div>\
						</div>\
						<div class="box-disk box-disk-bt">\
							<i class="box-disk-edge bt-left">&nbsp;</i>\
							<i class="box-disk-edge bt-right">&nbsp;</i>\
						</div>\
					</div>';
		str += getTopWinner4qb(fragment);	
		str += '</div></div>';
			
		return str;
	}
	
})(jQuery);

